#pragma once

#include <sys_reg.h>

typedef enum {
	ECLIC_CLICCFG_R = 0x0,
	ECLIC_CLICINFO_R = 0x4,
	ECLIC_MTH_R = 0xB,
	ECLIC_CLICINT_R = 0x1000,
} eclic_re;

static inline u32_s eclic_get_reg_q_by_q(u32_s eclic_q, eclic_re eclic_r,
					 u32_s byte_r) {
	return eclic_q + eclic_r + byte_r;
}

static inline void eclic_wreg_by_q(u32_s eclic_q, eclic_re eclic_r,
				   u32_s value) {
	u32_s reg_q = eclic_get_reg_q_by_q(eclic_q, eclic_r, 0);
	wreg(reg_q, value);
}

static inline void eclic_wreg_u8_by_q(u32_s eclic_q, eclic_re eclic_r,
				      t8b_re byte_r, u32_s value) {
	u32_s reg_q = eclic_get_reg_q_by_q(eclic_q, eclic_r, byte_r);
	wreg_u8(reg_q, value);
}

static inline void eclic_wreg_u16_by_q(u32_s eclic_q, eclic_re eclic_r,
				       t16b_re byte_r, u32_s value) {
	u32_s reg_q = eclic_get_reg_q_by_q(eclic_q, eclic_r, byte_r);
	wreg_u16(reg_q, value);
}

static inline u32_s eclic_rreg_by_q(u32_s eclic_q, eclic_re eclic_r) {
	u32_s reg_q = eclic_get_reg_q_by_q(eclic_q, eclic_r, 0);
	return rreg(reg_q);
}

static inline u32_s eclic_rreg_u8_by_q(u32_s eclic_q, eclic_re eclic_r,
				       t8b_re byte_r) {
	u32_s reg_q = eclic_get_reg_q_by_q(eclic_q, eclic_r, byte_r);
	return rreg_u8(reg_q);
}

static inline u32_s eclic_rreg_u16_by_q(u32_s eclic_q, eclic_re eclic_r,
					t16b_re byte_r) {
	u32_s reg_q = eclic_get_reg_q_by_q(eclic_q, eclic_r, byte_r);
	return rreg_u16(reg_q);
}
